#ifndef CNOTEDISPLAYMANAGER_H
#define CNOTEDISPLAYMANAGER_H

//#include <QObject>
#include <MApplicationPage>
#include "QvernoteAPI.h"
//#include "QvernoteWindow.h"
#include "widgets/CNoteDisplayWidget.h"
#include "widgets/CNoteInfoPanel.h"

/*
 Note Display manager

 Construction:
    Main widget
    Secondary widget  - either appended to the right or left of the main widget
    Note info pane - appears when note is scrolled to top and dissapears when note is scrolling down

    Main widget is always visible, secondary widget becomes visible on main widget shift.
    Secondary widget becomes main widget when shift delta is over threshold.
    On secondary widget dissapearing, its contents are erased to preserve memory.

    Both widgets are drawn upon CentralWidget widget

 Base services:
    Shift ( offset, delta ) - Shifts the main widget left or right (depending on x-offset). Together with
        main widget, secondary widget appears / shits too. When x-offset is zero, secondary widget is deleted

    SwitchWidget() - Switches to secondary widget with animation.

    AppendWidgetLeft() - Creates a secondary widget with previous note contents
    AppendWidgetRight() - Creates a secondary widget with next note contents

    GetMainWidget() - return the main widget
    GetSecondaryWidget() - return the secondary widget

 */
class CNoteDisplayManager : public QObject
{
    Q_OBJECT

public:
    struct NoteWidget {
        CNoteDisplayWidget*     noteWidget;
        QPropertyAnimation*     noteAnim;
        Note                    note;
    };

public:
    enum NoteWidgetId { Main = 0, Secondary = 1 };
    enum NotePanDirection { Left, Right };

public:
    CNoteDisplayManager(Note& note, MApplicationPage* parent);
    virtual ~CNoteDisplayManager();

    void Shift(int offset, int delta);
    void switchWidget();
    void resetWidget();
    void appendWidgetLeft();
    void appendWidgetRight();
    void scaleWidget(qreal);

    CNoteDisplayWidget* getMainWidget();
    CNoteDisplayWidget* getSecondaryWidget();

    bool isSwitchWidgetNeeded();

    Note& GetCurrentNote();
    void  HideInfoPane();

private:
    void destroyWidget(NoteWidgetId widgetId);
    void destroyAnimation(NoteWidgetId widgetId);

public slots:
    /* Various callbacks for animation targets */
    void doSwitchWidget();
    void doResetWidget();

signals:
    void animationDone(Qt::GestureType gestureType);

private:
    NoteWidget              noteDisplayWidgetTable[2];
    QvernoteAPI*            m_hEvernote;
    NotePanDirection        m_currentPanDirection;
    int                     m_lastOffset;
    int                     m_initialPanDirection;
    MApplicationPage*       m_parent;
    //CNoteWidgetAnimation*   m_noteWidgetAnim;
    QParallelAnimationGroup m_animationGroup;
    CNoteInfoPanel*         m_noteInfoPanel;
};

#endif // CNOTEDISPLAYMANAGER_H
